package org.dlsu.mt.parser;

/**
 * A sample implementation of FStructureElementValue interface that represents an attribute with an arbitrary String value
 */
public class FStructureElementString extends FStructureElementValue {
	/** A String value */
	protected String value;

	/**
	 * Creates a new FStructureElementString given the specified string value
	 *
	 * @param value The value to convert to FStructureElementString
	 */
	public FStructureElementString(String value) {
		this.value = value;
	}

	/**
	 * Returns the string value stored inside the FStructureElementString
	 *
	 * @return The string value stored inside the FStructureElementString
	 */
	public Object getValue() {
		return value;
	}

	/**
	 * Sets the FStructureElementString to its a new value
	 *
	 * @param value Set a new string value
	 */
	public void setValue(Object value) {
		this.value = value.toString();
	}

	/**
	 * Returns the hashcode of the stored string
	 *
	 * @return The hashcode of the current object
	 */
	public int hashCode() {
		return value.hashCode();
	}

	/**
	 * Compares whether two FStructureElementString are equal by comparing their values.
	 *
	 * @param obj The target object to compare with
	 * @return True when equal otherwise false
	 */
	public boolean equals(Object obj) {
		try {
			return value.equals( ((FStructureElementString) obj).value );
		} catch(Exception e) {
			return false;
		}
	}

	/**
	 * Returns the XML representation of the class in the form:
	 * <VALUE> <string value> </VALUE>
	 *
	 * @return The XML representation of the object
	 */
	public String toXML() {
		return "<VALUE>"+value+"</VALUE>";
	}

	/**
	 * Returns the String representation of the class in the form:
	 *	 <string value>
	 *
	 * @return The string representation of the object
	 */
	public String toString() {
		return value;
	}

	/**
	 * Creates a copy of the object
	 *
	 * @return A copy of the current object
	 */
	public Object clone() {
		return new FStructureElementString(value);
	}
}